package dict

import (
	"context"
	"github.com/ifnk/micro-blog/internal/pkg/config"
	"github.com/ifnk/micro-blog/internal/pkg/log"
	"github.com/ifnk/micro-blog/protobuf/dict_pb"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"time"
)

func NewDictClient(logger *log.Logger, conf *config.Config) (dict_pb.DictServiceClient, error) {
	ctx, cancel := context.WithTimeout(context.Background(), 80*time.Second)
	defer cancel()
	conn, err := grpc.DialContext(ctx, conf.Dict.Server.Host+conf.Dict.Server.GRPC.Port, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		return nil, err
	}
	client := dict_pb.NewDictServiceClient(conn)
	return client, err
}
func NewDictDetailClient(logger *log.Logger, conf *config.Config) (dict_pb.DictDetailServiceClient, error) {
	ctx, cancel := context.WithTimeout(context.Background(), 80*time.Second)
	defer cancel()
	conn, err := grpc.DialContext(ctx, conf.Dict.Server.Host+conf.Dict.Server.GRPC.Port, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		return nil, err
	}
	client := dict_pb.NewDictDetailServiceClient(conn)
	return client, err
}
